package com.itheima.sc.service.sms;

import cn.hutool.core.convert.Convert;
import com.itheima.sc.api.sms.SmsHomeBrandApi;
import com.itheima.sc.pojo.sms.HomeBrand;
import com.itheima.sc.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SmsHomeBrandService {

    @DubboReference
    private SmsHomeBrandApi homeBrandApi;


    //添加首页推荐品牌
    public void addBrand(List<HomeBrand> homeBrands) {
        homeBrandApi.addBrand(homeBrands);
    }

    //批量删除首页推荐品牌
    public void deleteBrands(List<Long> ids) {
        //1.首先查询推荐品牌的ids
//       List<Long> brandIds=homeBrandApi.selectBrands(ids);
       homeBrandApi.deleteBrands(ids);
    }

    //查询首页推荐品牌的列表
    public PageResult selectBrandList(Map<String, String> param) {
        String brandName = param.get("brandName");
        Integer page = Convert.toInt(param.get("pageNum"));
        Integer pageSize = Convert.toInt(param.get("pageSize"));
        Integer recommendStatus = Convert.toInt(param.get("recommendStatus"));
        return homeBrandApi.selectBrandList(page, pageSize, recommendStatus,brandName);
    }

    //批量修改品牌的状态
    public void updateBrandStatus(List<Long> ids, Integer status) {
      homeBrandApi.updateBrandStatus(ids,status);
    }

    //修改推荐品牌的排序
    public void updateBrandSort(Long id, Integer sort) {
        HomeBrand homeBrand=new HomeBrand();
        homeBrand.setId(id);
        homeBrand.setSort(sort);
        homeBrandApi.updateBrandSort(homeBrand);
    }
}
